package one.chapter_1;

import java.util.Random;

public class TwoSum {

    public static void main(String []args){
        int a[] =new int [1000];
        Random random=new Random();
        for (int i=0;i<1000;i++){
            a[i]=random.nextInt(200)-100;
            System.out.println(a[i]);
        }



        Stopwatch stopwatch=new Stopwatch();
        int total=twoSum(a);
        System.out.println("total:"+total+"---执行时间:"+stopwatch.elapsedTime()+"s");


    }

    private static int twoSum(int[] a) {
        int total=0;
        for (int i=0;i<a.length;i++){
            for (int j=i+1;j<a.length;j++){   //(n^2/2+n/2)
                if (a[i]+a[j]==0){
                    total++;
                }
            }
        }

        return total;

    }


}
